home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / doom / quake1.zip / TRACBEAM.ZIP / SRC / WEAPONS.QC < prev   
Text File  |  1996-08-26  |  28KB  |  1,322 lines

  1. /*
  2. */
  3. void (entity targ, entity inflictor, entity attacker, float damage) T_Damage;
  4. void () player_run;
  5. void(entity bomb, entity attacker, float rad, entity ignore) T_RadiusDamage;
  6. void(vector org, vector vel, float damage) SpawnBlood;
  7. void() SuperDamageSound;
  8.  
  9.  
  10. // called by worldspawn
  11. void() W_Precache =
  12. {
  13.     precache_sound ("weapons/r_exp3.wav");    // new rocket explosion
  14.     precache_sound ("weapons/rocket1i.wav");    // spike gun
  15.     precache_sound ("weapons/sgun1.wav");
  16.     precache_sound ("weapons/guncock.wav");    // player shotgun
  17.     precache_sound ("weapons/ric1.wav");    // ricochet (used in c code)
  18.     precache_sound ("weapons/ric2.wav");    // ricochet (used in c code)
  19.     precache_sound ("weapons/ric3.wav");    // ricochet (used in c code)
  20.     precache_sound ("weapons/spike2.wav");    // super spikes
  21.     precache_sound ("weapons/tink1.wav");    // spikes tink (used in c code)
  22.     precache_sound ("weapons/grenade.wav");    // grenade launcher
  23.     precache_sound ("weapons/bounce.wav");        // grenade bounce
  24.     precache_sound ("weapons/shotgn2.wav");    // super shotgun
  25. };
  26.  
  27. float() crandom =
  28. {
  29.     return 2*(random() - 0.5);
  30. };
  31.  
  32. /*
  33. ================
  34. W_FireAxe
  35. ================
  36. */
  37. void() W_FireAxe =
  38. {
  39.     local    vector    source;
  40.     local    vector    org;
  41.  
  42.     source = self.origin + '0 0 16';
  43.     traceline (source, source + v_forward*64, FALSE, self);
  44.     if (trace_fraction == 1.0)
  45.         return;
  46.     
  47.     org = trace_endpos - v_forward*4;
  48.  
  49.     if (trace_ent.takedamage)
  50.     {
  51.         trace_ent.axhitme = 1;
  52.         SpawnBlood (org, '0 0 0', 20);
  53.         T_Damage (trace_ent, self, self, 20);
  54.     }
  55.     else
  56.     {    // hit wall
  57.         sound (self, CHAN_WEAPON, "player/axhit2.wav", 1, ATTN_NORM);
  58.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  59.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  60.         WriteCoord (MSG_BROADCAST, org_x);
  61.         WriteCoord (MSG_BROADCAST, org_y);
  62.         WriteCoord (MSG_BROADCAST, org_z);
  63.     }
  64. };
  65.  
  66.  
  67. //============================================================================
  68.  
  69.  
  70. vector() wall_velocity =
  71. {
  72.     local vector    vel;
  73.     
  74.     vel = normalize (self.velocity);
  75.     vel = normalize(vel + v_up*(random()- 0.5) + v_right*(random()- 0.5));
  76.     vel = vel + 2*trace_plane_normal;
  77.     vel = vel * 200;
  78.     
  79.     return vel;
  80. };
  81.  
  82.  
  83. /*
  84. ================
  85. SpawnMeatSpray
  86. ================
  87. */
  88. void(vector org, vector vel) SpawnMeatSpray =
  89. {
  90.     local    entity missile, mpuff;
  91.     local    vector    org;
  92.  
  93.     missile = spawn ();
  94.     missile.owner = self;
  95.     missile.movetype = MOVETYPE_BOUNCE;
  96.     missile.solid = SOLID_NOT;
  97.  
  98.     makevectors (self.angles);
  99.  
  100.     missile.velocity = vel;
  101.     missile.velocity_z = missile.velocity_z + 250 + 50*random();
  102.  
  103.     missile.avelocity = '3000 1000 2000';
  104.     
  105. // set missile duration
  106.     missile.nextthink = time + 1;
  107.     missile.think = SUB_Remove;
  108.  
  109.     setmodel (missile, "progs/zom_gib.mdl");
  110.     setsize (missile, '0 0 0', '0 0 0');        
  111.     setorigin (missile, org);
  112. };
  113.  
  114. /*
  115. ================
  116. SpawnBlood
  117. ================
  118. */
  119. void(vector org, vector vel, float damage) SpawnBlood =
  120. {
  121.     particle (org, vel*0.1, 73, damage*2);
  122. };
  123.  
  124. /*
  125. ================
  126. spawn_touchblood
  127. ================
  128. */
  129. void(float damage) spawn_touchblood =
  130. {
  131.     local vector    vel;
  132.  
  133.     vel = wall_velocity () * 0.2;
  134.     SpawnBlood (self.origin + vel*0.01, vel, damage);
  135. };
  136.  
  137.  
  138. /*
  139. ================
  140. SpawnChunk
  141. ================
  142. */
  143. void(vector org, vector vel) SpawnChunk =
  144. {
  145.     particle (org, vel*0.02, 0, 10);
  146. };
  147.  
  148. /*
  149. ==============================================================================
  150.  
  151. MULTI-DAMAGE
  152.  
  153. Collects multiple small damages into a single damage
  154.  
  155. ==============================================================================
  156. */
  157.  
  158. entity    multi_ent;
  159. float    multi_damage;
  160.  
  161. void() ClearMultiDamage =
  162. {
  163.     multi_ent = world;
  164.     multi_damage = 0;
  165. };
  166.  
  167. void() ApplyMultiDamage =
  168. {
  169.     if (!multi_ent)
  170.         return;
  171.     T_Damage (multi_ent, self, self, multi_damage);
  172. };
  173.  
  174. void(entity hit, float damage) AddMultiDamage =
  175. {
  176.     if (!hit)
  177.         return;
  178.     
  179.     if (hit != multi_ent)
  180.     {
  181.         ApplyMultiDamage ();
  182.         multi_damage = damage;
  183.         multi_ent = hit;
  184.     }
  185.     else
  186.         multi_damage = multi_damage + damage;
  187. };
  188.  
  189. /*
  190. ==============================================================================
  191.  
  192. BULLETS
  193.  
  194. ==============================================================================
  195. */
  196.  
  197. /*
  198. ================
  199. TraceAttack
  200. ================
  201. */
  202. void(float damage, vector dir) TraceAttack =
  203. {
  204.     local    vector    vel, org;
  205.     
  206.     vel = normalize(dir + v_up*crandom() + v_right*crandom());
  207.     vel = vel + 2*trace_plane_normal;
  208.     vel = vel * 200;
  209.  
  210.     org = trace_endpos - dir*4;
  211.  
  212.     if (trace_ent.takedamage)
  213.     {
  214.         SpawnBlood (org, vel*0.2, damage);
  215.         AddMultiDamage (trace_ent, damage);
  216.     }
  217.     else
  218.     {
  219.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  220.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  221.         WriteCoord (MSG_BROADCAST, org_x);
  222.         WriteCoord (MSG_BROADCAST, org_y);
  223.         WriteCoord (MSG_BROADCAST, org_z);
  224.     }
  225. };
  226.  
  227. /*
  228. ================
  229. FireBullets
  230.  
  231. Used by shotgun, super shotgun, and enemy soldier firing
  232. Go to the trouble of combining multiple pellets into a single damage call.
  233. ================
  234. */
  235. void(float shotcount, vector dir, vector spread) FireBullets =
  236. {
  237.     local    vector direction;
  238.     local    vector    src;
  239.     
  240.     makevectors(self.v_angle);
  241.  
  242.     src = self.origin + v_forward*10;
  243.     src_z = self.absmin_z + self.size_z * 0.7;
  244.  
  245.     ClearMultiDamage ();
  246.     while (shotcount > 0)
  247.     {
  248.         direction = dir + crandom()*spread_x*v_right + crandom()*spread_y*v_up;
  249.  
  250.         traceline (src, src + direction*2048, FALSE, self);
  251.         if (trace_fraction != 1.0)
  252.             TraceAttack (4, direction);
  253.  
  254.         shotcount = shotcount - 1;
  255.     }
  256.     ApplyMultiDamage ();
  257. };
  258.  
  259. /*
  260. ================
  261. W_FireShotgun
  262. ================
  263. */
  264. void() W_FireShotgun =
  265. {
  266.     local vector dir;
  267.  
  268.     sound (self, CHAN_WEAPON, "weapons/guncock.wav", 1, ATTN_NORM);    
  269.  
  270.     self.punchangle_x = -2;
  271.     
  272.     self.currentammo = self.ammo_shells = self.ammo_shells - 1;
  273.     dir = aim (self, 100000);
  274.     FireBullets (6, dir, '0.04 0.04 0');
  275. };
  276.  
  277.  
  278. /*
  279. ================
  280. W_FireSuperShotgun
  281. ================
  282. */
  283. void() W_FireSuperShotgun =
  284. {
  285.     local vector dir;
  286.  
  287.     if (self.currentammo == 1)
  288.     {
  289.         W_FireShotgun ();
  290.         return;
  291.     }
  292.         
  293.     sound (self ,CHAN_WEAPON, "weapons/shotgn2.wav", 1, ATTN_NORM);    
  294.  
  295.     self.punchangle_x = -4;
  296.     
  297.     self.currentammo = self.ammo_shells = self.ammo_shells - 2;
  298.     dir = aim (self, 100000);
  299.     FireBullets (14, dir, '0.14 0.08 0');
  300. };
  301.  
  302.  
  303. /*
  304. ==============================================================================
  305.  
  306. ROCKETS
  307.  
  308. ==============================================================================
  309. */
  310.  
  311. void()    s_explode1    =    [0,        s_explode2] {};
  312. void()    s_explode2    =    [1,        s_explode3] {};
  313. void()    s_explode3    =    [2,        s_explode4] {};
  314. void()    s_explode4    =    [3,        s_explode5] {};
  315. void()    s_explode5    =    [4,        s_explode6] {};
  316. void()    s_explode6    =    [5,        SUB_Remove] {};
  317.  
  318. void() BecomeExplosion =
  319. {
  320.     self.movetype = MOVETYPE_NONE;
  321.     self.velocity = '0 0 0';
  322.     self.touch = SUB_Null;
  323.     setmodel (self, "progs/s_explod.spr");
  324.     self.solid = SOLID_NOT;
  325.     s_explode1 ();
  326. };
  327.  
  328. void() T_MissileTouch =
  329. {
  330.     local float    damg;
  331.  
  332.     if (other == self.owner)
  333.         return;        // don't explode on owner
  334.  
  335.     if (pointcontents(self.origin) == CONTENT_SKY)
  336.     {
  337.         remove(self);
  338.         return;
  339.     }
  340.  
  341.     damg = 100 + random()*20;
  342.     
  343.     if (other.health)
  344.     {
  345.         if (other.classname == "monster_shambler")
  346.             damg = damg * 0.5;    // mostly immune
  347.         T_Damage (other, self, self.owner, damg );
  348.     }
  349.  
  350.     // don't do radius damage to the other, because all the damage
  351.     // was done in the impact
  352.     T_RadiusDamage (self, self.owner, 120, other);
  353.  
  354. //    sound (self, CHAN_WEAPON, "weapons/r_exp3.wav", 1, ATTN_NORM);
  355.     self.origin = self.origin - 8*normalize(self.velocity);
  356.  
  357.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  358.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  359.     WriteCoord (MSG_BROADCAST, self.origin_x);
  360.     WriteCoord (MSG_BROADCAST, self.origin_y);
  361.     WriteCoord (MSG_BROADCAST, self.origin_z);
  362.  
  363.     BecomeExplosion ();
  364. };
  365.  
  366.  
  367.  
  368. /*
  369. ================
  370. W_FireRocket
  371. ================
  372. */
  373. void() W_FireRocket =
  374. {
  375.     local    entity missile, mpuff;
  376.     
  377.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  378.     
  379.     sound (self, CHAN_WEAPON, "weapons/sgun1.wav", 1, ATTN_NORM);
  380.  
  381.     self.punchangle_x = -2;
  382.  
  383.     missile = spawn ();
  384.     missile.owner = self;
  385.     missile.movetype = MOVETYPE_FLYMISSILE;
  386.     missile.solid = SOLID_BBOX;
  387.         
  388. // set missile speed    
  389.  
  390.     makevectors (self.v_angle);
  391.     missile.velocity = aim(self, 1000);
  392.     missile.velocity = missile.velocity * 1000;
  393.     missile.angles = vectoangles(missile.velocity);
  394.     
  395.     missile.touch = T_MissileTouch;
  396.     
  397. // set missile duration
  398.     missile.nextthink = time + 5;
  399.     missile.think = SUB_Remove;
  400.  
  401.     setmodel (missile, "progs/missile.mdl");
  402.     setsize (missile, '0 0 0', '0 0 0');        
  403.     setorigin (missile, self.origin + v_forward*8 + '0 0 16');
  404. };
  405.  
  406. /*
  407. ===============================================================================
  408.  
  409. LIGHTNING
  410.  
  411. ===============================================================================
  412. */
  413.  
  414. /*
  415. =================
  416. LightningDamage
  417. =================
  418. */
  419. void() ChangeLightningMode =
  420. {
  421.         dprint("Changing thunderbolt mode to ");
  422.         if (self.items & IT_TRACTOR_BEAM)
  423.         {
  424.                 self.items = self.items - (self.items & IT_TRACTOR_BEAM);
  425.                 dprint("lightning.\n");
  426.         }
  427.         else
  428.         {
  429.                 self.items = self.items | IT_TRACTOR_BEAM;
  430.                 dprint("tractor beam.\n");
  431.         }
  432. };
  433.  
  434. void(vector p1, vector p2, entity from, float damage) TractorEffect =
  435. {
  436.     local entity        e1, e2;
  437.     local vector        f;
  438.  
  439.     f = p2 - p1;
  440.     normalize (f);
  441.     f_x = 0 - f_y;
  442.     f_y = f_x;
  443.     f_z = 0;
  444.     f = f*16;
  445.  
  446.     e1 = e2 = world;
  447.  
  448.     traceline (p1, p2, FALSE, self);
  449.     e1 = trace_ent;
  450.         if (trace_ent.takedamage && trace_ent.classname != "trigger_multiple" && trace_ent.classname != "door")
  451.         {
  452.                 trace_ent.origin = self.origin+v_forward*vlen(self.origin-trace_ent.origin);
  453.                 trace_ent.movetype = MOVETYPE_TOSS;
  454.                 trace_ent.nextthink = time + 0.5;
  455.     }
  456.  
  457.     traceline (p1 + f, p2 + f, FALSE, self);
  458.         if (trace_ent != e1 && trace_ent.takedamage && trace_ent.classname != "trigger_multiple" && trace_ent.classname != "door")
  459.     {
  460.                 trace_ent.origin = self.origin+v_forward*vlen(self.origin-trace_ent.origin);
  461.                 trace_ent.movetype = MOVETYPE_TOSS;
  462.                 trace_ent.nextthink = time + 0.5;
  463.     }
  464.     e2 = trace_ent;
  465.  
  466.     traceline (p1 - f, p2 - f, FALSE, self);
  467.         if (trace_ent != e1 && trace_ent != e2 && trace_ent.takedamage && trace_ent.classname != "trigger_multiple" && trace_ent.classname != "door")
  468.     {
  469.                 trace_ent.origin = self.origin+v_forward*vlen(self.origin-trace_ent.origin);
  470.                 trace_ent.movetype = MOVETYPE_TOSS;
  471.                 trace_ent.nextthink = time + 0.5;
  472.     }
  473. };
  474. void() W_UseTractor =
  475. {
  476.     local    vector        org;
  477.  
  478.         dprint("W_UseTractor running\n");
  479.     if (self.ammo_cells < 1)
  480.     {
  481.         self.weapon = W_BestWeapon ();
  482.         W_SetCurrentAmmo ();
  483.         return;
  484.     }
  485.  
  486.     if (self.t_width < time)
  487.     {
  488.         sound (self, CHAN_WEAPON, "weapons/lhit.wav", 1, ATTN_NORM);
  489.         self.t_width = time + 0.6;
  490.     }
  491.     self.punchangle_x = -2;
  492.  
  493.     self.currentammo = self.ammo_cells = self.ammo_cells - 1;
  494.  
  495.     org = self.origin + '0 0 16';
  496.  
  497.     traceline (org, org + v_forward*600, TRUE, self);
  498.  
  499.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  500.     WriteByte (MSG_BROADCAST, TE_LIGHTNING2);
  501.     WriteEntity (MSG_BROADCAST, self);
  502.     WriteCoord (MSG_BROADCAST, org_x);
  503.     WriteCoord (MSG_BROADCAST, org_y);
  504.     WriteCoord (MSG_BROADCAST, org_z);
  505.     WriteCoord (MSG_BROADCAST, trace_endpos_x);
  506.     WriteCoord (MSG_BROADCAST, trace_endpos_y);
  507.     WriteCoord (MSG_BROADCAST, trace_endpos_z);
  508.  
  509.     TractorEffect (self.origin, trace_endpos + v_forward*4, self, 30);
  510. };
  511.  
  512. void(vector p1, vector p2, entity from, float damage) LightningDamage =
  513. {
  514.     local entity        e1, e2;
  515.     local vector        f;
  516.  
  517.     f = p2 - p1;
  518.     normalize (f);
  519.     f_x = 0 - f_y;
  520.     f_y = f_x;
  521.     f_z = 0;
  522.     f = f*16;
  523.  
  524.     e1 = e2 = world;
  525.  
  526.     traceline (p1, p2, FALSE, self);
  527.     if (trace_ent.takedamage)
  528.     {
  529.         particle (trace_endpos, '0 0 100', 225, damage*4);
  530.         T_Damage (trace_ent, from, from, damage);
  531.         if (self.classname == "player")
  532.         {
  533.             if (other.classname == "player")
  534.                 trace_ent.velocity_z = trace_ent.velocity_z + 400;
  535.         }
  536.     }
  537.     e1 = trace_ent;
  538.  
  539.     traceline (p1 + f, p2 + f, FALSE, self);
  540.     if (trace_ent != e1 && trace_ent.takedamage)
  541.     {
  542.         particle (trace_endpos, '0 0 100', 225, damage*4);
  543.         T_Damage (trace_ent, from, from, damage);
  544.     }
  545.     e2 = trace_ent;
  546.  
  547.     traceline (p1 - f, p2 - f, FALSE, self);
  548.     if (trace_ent != e1 && trace_ent != e2 && trace_ent.takedamage)
  549.     {
  550.         particle (trace_endpos, '0 0 100', 225, damage*4);
  551.         T_Damage (trace_ent, from, from, damage);
  552.     }
  553. };
  554.  
  555.  
  556. void() W_FireLightning =
  557. {
  558.     local    vector        org;
  559.  
  560.         if (self.items & IT_TRACTOR_BEAM)
  561.         {
  562.                 W_UseTractor();
  563.                 return;
  564.         }
  565.  
  566.     if (self.ammo_cells < 1)
  567.     {
  568.         self.weapon = W_BestWeapon ();
  569.         W_SetCurrentAmmo ();
  570.         return;
  571.     }
  572.  
  573. // explode if under water
  574.     if (self.waterlevel > 1)
  575.     {
  576.         T_RadiusDamage (self, self, 35*self.ammo_cells, world);
  577.         self.ammo_cells = 0;
  578.         W_SetCurrentAmmo ();
  579.         return;
  580.     }
  581.  
  582.     if (self.t_width < time)
  583.     {
  584.         sound (self, CHAN_WEAPON, "weapons/lhit.wav", 1, ATTN_NORM);
  585.         self.t_width = time + 0.6;
  586.     }
  587.     self.punchangle_x = -2;
  588.  
  589.     self.currentammo = self.ammo_cells = self.ammo_cells - 1;
  590.  
  591.     org = self.origin + '0 0 16';
  592.  
  593.     traceline (org, org + v_forward*600, TRUE, self);
  594.  
  595.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  596.     WriteByte (MSG_BROADCAST, TE_LIGHTNING2);
  597.     WriteEntity (MSG_BROADCAST, self);
  598.     WriteCoord (MSG_BROADCAST, org_x);
  599.     WriteCoord (MSG_BROADCAST, org_y);
  600.     WriteCoord (MSG_BROADCAST, org_z);
  601.     WriteCoord (MSG_BROADCAST, trace_endpos_x);
  602.     WriteCoord (MSG_BROADCAST, trace_endpos_y);
  603.     WriteCoord (MSG_BROADCAST, trace_endpos_z);
  604.  
  605.     LightningDamage (self.origin, trace_endpos + v_forward*4, self, 30);
  606. };
  607.  
  608.  
  609. //=============================================================================
  610.  
  611.  
  612. void() GrenadeExplode =
  613. {
  614.     T_RadiusDamage (self, self.owner, 120, world);
  615.  
  616.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  617.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  618.     WriteCoord (MSG_BROADCAST, self.origin_x);
  619.     WriteCoord (MSG_BROADCAST, self.origin_y);
  620.     WriteCoord (MSG_BROADCAST, self.origin_z);
  621.  
  622.     BecomeExplosion ();
  623. };
  624.  
  625. void() GrenadeTouch =
  626. {
  627.     if (other == self.owner)
  628.         return;        // don't explode on owner
  629.     if (other.takedamage == DAMAGE_AIM)
  630.     {
  631.         GrenadeExplode();
  632.         return;
  633.     }
  634.     sound (self, CHAN_WEAPON, "weapons/bounce.wav", 1, ATTN_NORM);    // bounce sound
  635.     if (self.velocity == '0 0 0')
  636.         self.avelocity = '0 0 0';
  637. };
  638.  
  639. /*
  640. ================
  641. W_FireGrenade
  642. ================
  643. */
  644. void() W_FireGrenade =
  645. {
  646.     local    entity missile, mpuff;
  647.     
  648.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  649.     
  650.     sound (self, CHAN_WEAPON, "weapons/grenade.wav", 1, ATTN_NORM);
  651.  
  652.     self.punchangle_x = -2;
  653.  
  654.     missile = spawn ();
  655.     missile.owner = self;
  656.     missile.movetype = MOVETYPE_BOUNCE;
  657.     missile.solid = SOLID_BBOX;
  658.     missile.classname = "grenade";
  659.         
  660. // set missile speed    
  661.  
  662.     makevectors (self.v_angle);
  663.  
  664.     if (self.v_angle_x)
  665.         missile.velocity = v_forward*600 + v_up * 200 + crandom()*v_right*10 + crandom()*v_up*10;
  666.     else
  667.     {
  668.         missile.velocity = aim(self, 10000);
  669.         missile.velocity = missile.velocity * 600;
  670.         missile.velocity_z = 200;
  671.     }
  672.  
  673.     missile.avelocity = '300 300 300';
  674.  
  675.     missile.angles = vectoangles(missile.velocity);
  676.     
  677.     missile.touch = GrenadeTouch;
  678.     
  679. // set missile duration
  680.     missile.nextthink = time + 2.5;
  681.     missile.think = GrenadeExplode;
  682.  
  683.     setmodel (missile, "progs/grenade.mdl");
  684.     setsize (missile, '0 0 0', '0 0 0');        
  685.     setorigin (missile, self.origin);
  686. };
  687.  
  688.  
  689. //=============================================================================
  690.  
  691. void() spike_touch;
  692. void() superspike_touch;
  693.  
  694.  
  695. /*
  696. ===============
  697. launch_spike
  698.  
  699. Used for both the player and the ogre
  700. ===============
  701. */
  702. void(vector org, vector dir) launch_spike =
  703. {
  704.     newmis = spawn ();
  705.     newmis.owner = self;
  706.     newmis.movetype = MOVETYPE_FLYMISSILE;
  707.     newmis.solid = SOLID_BBOX;
  708.  
  709.     newmis.angles = vectoangles(dir);
  710.     
  711.     newmis.touch = spike_touch;
  712.     newmis.classname = "spike";
  713.     newmis.think = SUB_Remove;
  714.     newmis.nextthink = time + 6;
  715.     setmodel (newmis, "progs/spike.mdl");
  716.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);        
  717.     setorigin (newmis, org);
  718.  
  719.     newmis.velocity = dir * 1000;
  720. };
  721.  
  722. void() W_FireSuperSpikes =
  723. {
  724.     local vector    dir;
  725.     local entity    old;
  726.     
  727.     sound (self, CHAN_WEAPON, "weapons/spike2.wav", 1, ATTN_NORM);
  728.     self.attack_finished = time + 0.2;
  729.     self.currentammo = self.ammo_nails = self.ammo_nails - 2;
  730.     dir = aim (self, 1000);
  731.     launch_spike (self.origin + '0 0 16', dir);
  732.     newmis.touch = superspike_touch;
  733.     setmodel (newmis, "progs/s_spike.mdl");
  734.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);        
  735.     self.punchangle_x = -2;
  736. };
  737.  
  738. void(float ox) W_FireSpikes =
  739. {
  740.     local vector    dir;
  741.     local entity    old;
  742.     
  743.     makevectors (self.v_angle);
  744.     
  745.     if (self.ammo_nails >= 2 && self.weapon == IT_SUPER_NAILGUN)
  746.     {
  747.         W_FireSuperSpikes ();
  748.         return;
  749.     }
  750.  
  751.     if (self.ammo_nails < 1)
  752.     {
  753.         self.weapon = W_BestWeapon ();
  754.         W_SetCurrentAmmo ();
  755.         return;
  756.     }
  757.  
  758.     sound (self, CHAN_WEAPON, "weapons/rocket1i.wav", 1, ATTN_NORM);
  759.     self.attack_finished = time + 0.2;
  760.     self.currentammo = self.ammo_nails = self.ammo_nails - 1;
  761.     dir = aim (self, 1000);
  762.     launch_spike (self.origin + '0 0 16' + v_right*ox, dir);
  763.  
  764.     self.punchangle_x = -2;
  765. };
  766.  
  767.  
  768.  
  769. .float hit_z;
  770. void() spike_touch =
  771. {
  772. local float rand;
  773.     if (other == self.owner)
  774.         return;
  775.  
  776.     if (other.solid == SOLID_TRIGGER)
  777.         return;    // trigger field, do nothing
  778.  
  779.     if (pointcontents(self.origin) == CONTENT_SKY)
  780.     {
  781.         remove(self);
  782.         return;
  783.     }
  784.     
  785. // hit something that bleeds
  786.     if (other.takedamage)
  787.     {
  788.         spawn_touchblood (9);
  789.         T_Damage (other, self, self.owner, 9);
  790.     }
  791.     else
  792.     {
  793.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  794.         
  795.         if (self.classname == "wizspike")
  796.             WriteByte (MSG_BROADCAST, TE_WIZSPIKE);
  797.         else if (self.classname == "knightspike")
  798.             WriteByte (MSG_BROADCAST, TE_KNIGHTSPIKE);
  799.         else
  800.             WriteByte (MSG_BROADCAST, TE_SPIKE);
  801.         WriteCoord (MSG_BROADCAST, self.origin_x);
  802.         WriteCoord (MSG_BROADCAST, self.origin_y);
  803.         WriteCoord (MSG_BROADCAST, self.origin_z);
  804.     }
  805.  
  806.     remove(self);
  807.  
  808. };
  809.  
  810. void() superspike_touch =
  811. {
  812. local float rand;
  813.     if (other == self.owner)
  814.         return;
  815.  
  816.     if (other.solid == SOLID_TRIGGER)
  817.         return;    // trigger field, do nothing
  818.  
  819.     if (pointcontents(self.origin) == CONTENT_SKY)
  820.     {
  821.         remove(self);
  822.         return;
  823.     }
  824.     
  825. // hit something that bleeds
  826.     if (other.takedamage)
  827.     {
  828.         spawn_touchblood (18);
  829.         T_Damage (other, self, self.owner, 18);
  830.     }
  831.     else
  832.     {
  833.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  834.         WriteByte (MSG_BROADCAST, TE_SUPERSPIKE);
  835.         WriteCoord (MSG_BROADCAST, self.origin_x);
  836.         WriteCoord (MSG_BROADCAST, self.origin_y);
  837.         WriteCoord (MSG_BROADCAST, self.origin_z);
  838.     }
  839.  
  840.     remove(self);
  841.  
  842. };
  843.  
  844.  
  845. /*
  846. ===============================================================================
  847.  
  848. PLAYER WEAPON USE
  849.  
  850. ===============================================================================
  851. */
  852.  
  853. void() W_SetCurrentAmmo =
  854. {
  855.     player_run ();        // get out of any weapon firing states
  856.  
  857.     self.items = self.items - ( self.items & (IT_SHELLS | IT_NAILS | IT_ROCKETS | IT_CELLS) );
  858.     
  859.     if (self.weapon == IT_AXE)
  860.     {
  861.         self.currentammo = 0;
  862.         self.weaponmodel = "progs/v_axe.mdl";
  863.         self.weaponframe = 0;
  864.     }
  865.     else if (self.weapon == IT_SHOTGUN)
  866.     {
  867.         self.currentammo = self.ammo_shells;
  868.         self.weaponmodel = "progs/v_shot.mdl";
  869.         self.weaponframe = 0;
  870.         self.items = self.items | IT_SHELLS;
  871.     }
  872.     else if (self.weapon == IT_SUPER_SHOTGUN)
  873.     {
  874.         self.currentammo = self.ammo_shells;
  875.         self.weaponmodel = "progs/v_shot2.mdl";
  876.         self.weaponframe = 0;
  877.         self.items = self.items | IT_SHELLS;
  878.     }
  879.     else if (self.weapon == IT_NAILGUN)
  880.     {
  881.         self.currentammo = self.ammo_nails;
  882.         self.weaponmodel = "progs/v_nail.mdl";
  883.         self.weaponframe = 0;
  884.         self.items = self.items | IT_NAILS;
  885.     }
  886.     else if (self.weapon == IT_SUPER_NAILGUN)
  887.     {
  888.         self.currentammo = self.ammo_nails;
  889.         self.weaponmodel = "progs/v_nail2.mdl";
  890.         self.weaponframe = 0;
  891.         self.items = self.items | IT_NAILS;
  892.     }
  893.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  894.     {
  895.         self.currentammo = self.ammo_rockets;
  896.         self.weaponmodel = "progs/v_rock.mdl";
  897.         self.weaponframe = 0;
  898.         self.items = self.items | IT_ROCKETS;
  899.     }
  900.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  901.     {
  902.         self.currentammo = self.ammo_rockets;
  903.         self.weaponmodel = "progs/v_rock2.mdl";
  904.         self.weaponframe = 0;
  905.         self.items = self.items | IT_ROCKETS;
  906.     }
  907.     else if (self.weapon == IT_LIGHTNING)
  908.     {
  909.         self.currentammo = self.ammo_cells;
  910.         self.weaponmodel = "progs/v_light.mdl";
  911.         self.weaponframe = 0;
  912.         self.items = self.items | IT_CELLS;
  913.     }
  914.     else
  915.     {
  916.         self.currentammo = 0;
  917.         self.weaponmodel = "";
  918.         self.weaponframe = 0;
  919.     }
  920. };
  921.  
  922. float() W_BestWeapon =
  923. {
  924.     local    float    it;
  925.     
  926.     it = self.items;
  927.  
  928.     if(self.ammo_cells >= 1 && (it & IT_LIGHTNING) )
  929.         return IT_LIGHTNING;
  930.     else if(self.ammo_nails >= 2 && (it & IT_SUPER_NAILGUN) )
  931.         return IT_SUPER_NAILGUN;
  932.     else if(self.ammo_shells >= 2 && (it & IT_SUPER_SHOTGUN) )
  933.         return IT_SUPER_SHOTGUN;
  934.     else if(self.ammo_nails >= 1 && (it & IT_NAILGUN) )
  935.         return IT_NAILGUN;
  936.     else if(self.ammo_shells >= 1 && (it & IT_SHOTGUN) )
  937.         return IT_SHOTGUN;
  938.         
  939. /*
  940.     if(self.ammo_rockets >= 1 && (it & IT_ROCKET_LAUNCHER) )
  941.         return IT_ROCKET_LAUNCHER;
  942.     else if(self.ammo_rockets >= 1 && (it & IT_GRENADE_LAUNCHER) )
  943.         return IT_GRENADE_LAUNCHER;
  944.  
  945. */
  946.  
  947.     return IT_AXE;
  948. };
  949.  
  950. float() W_CheckNoAmmo =
  951. {
  952.     if (self.currentammo > 0)
  953.         return TRUE;
  954.  
  955.     if (self.weapon == IT_AXE)
  956.         return TRUE;
  957.     
  958.     self.weapon = W_BestWeapon ();
  959.  
  960.     W_SetCurrentAmmo ();
  961.     
  962. // drop the weapon down
  963.     return FALSE;
  964. };
  965.  
  966. /*
  967. ============
  968. W_Attack
  969.  
  970. An attack impulse can be triggered now
  971. ============
  972. */
  973. void()    player_axe1;
  974. void()    player_axeb1;
  975. void()    player_axec1;
  976. void()    player_axed1;
  977. void()    player_shot1;
  978. void()    player_nail1;
  979. void()    player_light1;
  980. void()    player_rocket1;
  981.  
  982. void() W_Attack =
  983. {
  984.     local    float    r;
  985.  
  986.     if (!W_CheckNoAmmo ())
  987.         return;
  988.  
  989.     makevectors    (self.v_angle);            // calculate forward angle for velocity
  990.     self.show_hostile = time + 1;    // wake monsters up
  991.  
  992.     if (self.weapon == IT_AXE)
  993.     {
  994.         sound (self, CHAN_WEAPON, "weapons/ax1.wav", 1, ATTN_NORM);
  995.         r = random();
  996.         if (r < 0.25)
  997.             player_axe1 ();
  998.         else if (r<0.5)
  999.             player_axeb1 ();
  1000.         else if (r<0.75)
  1001.             player_axec1 ();
  1002.         else
  1003.             player_axed1 ();
  1004.         self.attack_finished = time + 0.5;
  1005.     }
  1006.     else if (self.weapon == IT_SHOTGUN)
  1007.     {
  1008.         player_shot1 ();
  1009.         W_FireShotgun ();
  1010.         self.attack_finished = time + 0.5;
  1011.     }
  1012.     else if (self.weapon == IT_SUPER_SHOTGUN)
  1013.     {
  1014.         player_shot1 ();
  1015.         W_FireSuperShotgun ();
  1016.         self.attack_finished = time + 0.7;
  1017.     }
  1018.     else if (self.weapon == IT_NAILGUN)
  1019.     {
  1020.         player_nail1 ();
  1021.     }
  1022.     else if (self.weapon == IT_SUPER_NAILGUN)
  1023.     {
  1024.         player_nail1 ();
  1025.     }
  1026.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  1027.     {
  1028.         player_rocket1();
  1029.         W_FireGrenade();
  1030.         self.attack_finished = time + 0.6;
  1031.     }
  1032.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  1033.     {
  1034.         player_rocket1();
  1035.         W_FireRocket();
  1036.         self.attack_finished = time + 0.8;
  1037.     }
  1038.     else if (self.weapon == IT_LIGHTNING)
  1039.     {
  1040.         player_light1();
  1041.         self.attack_finished = time + 0.1;
  1042.         sound (self, CHAN_AUTO, "weapons/lstart.wav", 1, ATTN_NORM);
  1043.     }
  1044. };
  1045.  
  1046. /*
  1047. ============
  1048. W_ChangeWeapon
  1049.  
  1050. ============
  1051. */
  1052. void() W_ChangeWeapon =
  1053. {
  1054.     local    float    it, am, fl;
  1055.     
  1056.     it = self.items;
  1057.     am = 0;
  1058.     
  1059.     if (self.impulse == 1)
  1060.     {
  1061.         fl = IT_AXE;
  1062.     }
  1063.     else if (self.impulse == 2)
  1064.     {
  1065.         fl = IT_SHOTGUN;
  1066.         if (self.ammo_shells < 1)
  1067.             am = 1;
  1068.     }
  1069.     else if (self.impulse == 3)
  1070.     {
  1071.         fl = IT_SUPER_SHOTGUN;
  1072.         if (self.ammo_shells < 2)
  1073.             am = 1;
  1074.     }        
  1075.     else if (self.impulse == 4)
  1076.     {
  1077.         fl = IT_NAILGUN;
  1078.         if (self.ammo_nails < 1)
  1079.             am = 1;
  1080.     }
  1081.     else if (self.impulse == 5)
  1082.     {
  1083.         fl = IT_SUPER_NAILGUN;
  1084.         if (self.ammo_nails < 2)
  1085.             am = 1;
  1086.     }
  1087.     else if (self.impulse == 6)
  1088.     {
  1089.         fl = IT_GRENADE_LAUNCHER;
  1090.         if (self.ammo_rockets < 1)
  1091.             am = 1;
  1092.     }
  1093.     else if (self.impulse == 7)
  1094.     {
  1095.         fl = IT_ROCKET_LAUNCHER;
  1096.         if (self.ammo_rockets < 1)
  1097.             am = 1;
  1098.     }
  1099.     else if (self.impulse == 8)
  1100.     {
  1101.         fl = IT_LIGHTNING;
  1102.         if (self.ammo_cells < 1)
  1103.             am = 1;
  1104.     }
  1105.  
  1106.     self.impulse = 0;
  1107.     
  1108.     if (!(self.items & fl))
  1109.     {    // don't have the weapon or the ammo
  1110.         sprint (self, "no weapon.\n");
  1111.         return;
  1112.     }
  1113.     
  1114.     if (am)
  1115.     {    // don't have the ammo
  1116.         sprint (self, "not enough ammo.\n");
  1117.         return;
  1118.     }
  1119.  
  1120. //
  1121. // set weapon, set ammo
  1122. //
  1123.     self.weapon = fl;        
  1124.     W_SetCurrentAmmo ();
  1125. };
  1126.  
  1127. /*
  1128. ============
  1129. CheatCommand
  1130. ============
  1131. */
  1132. void() CheatCommand =
  1133. {
  1134.     if (deathmatch || coop)
  1135.         return;
  1136.  
  1137.     self.ammo_rockets = 100;
  1138.     self.ammo_nails = 200;
  1139.     self.ammo_shells = 100;
  1140.     self.items = self.items | 
  1141.         IT_AXE |
  1142.         IT_SHOTGUN |
  1143.         IT_SUPER_SHOTGUN |
  1144.         IT_NAILGUN |
  1145.         IT_SUPER_NAILGUN |
  1146.         IT_GRENADE_LAUNCHER |
  1147.         IT_ROCKET_LAUNCHER |
  1148.         IT_KEY1 | IT_KEY2;
  1149.  
  1150.     self.ammo_cells = 200;
  1151.     self.items = self.items | IT_LIGHTNING;
  1152.  
  1153.     self.weapon = IT_ROCKET_LAUNCHER;
  1154.     self.impulse = 0;
  1155.     W_SetCurrentAmmo ();
  1156. };
  1157.  
  1158. /*
  1159. ============
  1160. CycleWeaponCommand
  1161.  
  1162. Go to the next weapon with ammo
  1163. ============
  1164. */
  1165. void() CycleWeaponCommand =
  1166. {
  1167.     local    float    it, am;
  1168.     
  1169.     it = self.items;
  1170.     self.impulse = 0;
  1171.     
  1172.     while (1)
  1173.     {
  1174.         am = 0;
  1175.  
  1176.         if (self.weapon == IT_LIGHTNING)
  1177.         {
  1178.             self.weapon = IT_AXE;
  1179.         }
  1180.         else if (self.weapon == IT_AXE)
  1181.         {
  1182.             self.weapon = IT_SHOTGUN;
  1183.             if (self.ammo_shells < 1)
  1184.                 am = 1;
  1185.         }
  1186.         else if (self.weapon == IT_SHOTGUN)
  1187.         {
  1188.             self.weapon = IT_SUPER_SHOTGUN;
  1189.             if (self.ammo_shells < 2)
  1190.                 am = 1;
  1191.         }        
  1192.         else if (self.weapon == IT_SUPER_SHOTGUN)
  1193.         {
  1194.             self.weapon = IT_NAILGUN;
  1195.             if (self.ammo_nails < 1)
  1196.                 am = 1;
  1197.         }
  1198.         else if (self.weapon == IT_NAILGUN)
  1199.         {
  1200.             self.weapon = IT_SUPER_NAILGUN;
  1201.             if (self.ammo_nails < 2)
  1202.                 am = 1;
  1203.         }
  1204.         else if (self.weapon == IT_SUPER_NAILGUN)
  1205.         {
  1206.             self.weapon = IT_GRENADE_LAUNCHER;
  1207.             if (self.ammo_rockets < 1)
  1208.                 am = 1;
  1209.         }
  1210.         else if (self.weapon == IT_GRENADE_LAUNCHER)
  1211.         {
  1212.             self.weapon = IT_ROCKET_LAUNCHER;
  1213.             if (self.ammo_rockets < 1)
  1214.                 am = 1;
  1215.         }
  1216.         else if (self.weapon == IT_ROCKET_LAUNCHER)
  1217.         {
  1218.             self.weapon = IT_LIGHTNING;
  1219.             if (self.ammo_cells < 1)
  1220.                 am = 1;
  1221.         }
  1222.     
  1223.         if ( (self.items & self.weapon) && am == 0)
  1224.         {
  1225.             W_SetCurrentAmmo ();
  1226.             return;
  1227.         }
  1228.     }
  1229.  
  1230. };
  1231.  
  1232. /*
  1233. ============
  1234. ServerflagsCommand
  1235.  
  1236. Just for development
  1237. ============
  1238. */
  1239. void() ServerflagsCommand =
  1240. {
  1241.     serverflags = serverflags * 2 + 1;
  1242. };
  1243.  
  1244. void() QuadCheat =
  1245. {
  1246.     if (deathmatch || coop)
  1247.         return;
  1248.     self.super_time = 1;
  1249.     self.super_damage_finished = time + 30;
  1250.     self.items = self.items | IT_QUAD;
  1251.     dprint ("quad cheat\n");
  1252. };
  1253.  
  1254. /*
  1255. ============
  1256. ImpulseCommands
  1257.  
  1258. ============
  1259. */
  1260. void() ImpulseCommands =
  1261. {
  1262.     if (self.impulse >= 1 && self.impulse <= 8)
  1263.         W_ChangeWeapon ();
  1264.  
  1265.     if (self.impulse == 9)
  1266.         CheatCommand ();
  1267.     if (self.impulse == 10)
  1268.         CycleWeaponCommand ();
  1269.     if (self.impulse == 11)
  1270.         ServerflagsCommand ();
  1271.     if (self.impulse == 15)
  1272.                 ChangeLightningMode();
  1273.     if (self.impulse == 255)
  1274.         QuadCheat ();
  1275.         
  1276.     self.impulse = 0;
  1277. };
  1278.  
  1279. /*
  1280. ============
  1281. W_WeaponFrame
  1282.  
  1283. Called every frame so impulse events can be handled as well as possible
  1284. ============
  1285. */
  1286. void() W_WeaponFrame =
  1287. {
  1288.     if (time < self.attack_finished)
  1289.         return;
  1290.  
  1291.     ImpulseCommands ();
  1292.     
  1293. // check for attack
  1294.     if (self.button0)
  1295.     {
  1296.         SuperDamageSound ();
  1297.         W_Attack ();
  1298.     }
  1299. };
  1300.  
  1301. /*
  1302. ========
  1303. SuperDamageSound
  1304.  
  1305. Plays sound if needed
  1306. ========
  1307. */
  1308. void() SuperDamageSound =
  1309. {
  1310.     if (self.super_damage_finished > time)
  1311.     {
  1312.         if (self.super_sound < time)
  1313.         {
  1314.             self.super_sound = time + 1;
  1315.             sound (self, CHAN_BODY, "items/damage3.wav", 1, ATTN_NORM);
  1316.         }
  1317.     }
  1318.     return;
  1319. };
  1320.  
  1321.  
  1322.